package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.Keyword;
import com.cskaoyan.bean.KeywordlistVO;
import com.cskaoyan.service.KeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/keyword")
public class KeywordController {
    @Autowired
    KeywordService keywordService;

    /**
     *关键词
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo keywordList(Integer page,Integer limit,String sort,String order,String keyword ,String url){
        KeywordlistVO<Keyword> keywordlistVO=keywordService.queryKeywordList(page,limit,sort,order,keyword,url);
        return BaseRespVo.ok(keywordlistVO);
    }

    /**
     * 新增关键词
     * @param keyword
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo createKeyword(@RequestBody Keyword keyword){
       Keyword newkeyword=keywordService.createKeyword(keyword);
       return BaseRespVo.ok(newkeyword);
    }

    /**
     * 更新关键词
     * @param keyword
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo updateKeyword(@RequestBody Keyword keyword){
        Keyword updateKeyword=keywordService.updateKeyword(keyword);
            return BaseRespVo.ok(updateKeyword);
        }
    @RequestMapping("delete")
    public BaseRespVo deleteKeyword(@RequestBody Keyword keyword) {
        int delete = keywordService.deleteKeyword(keyword);
        if (delete == 1) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("删除失败");
    }

    }


